package com.fmy.mcsecurity.config;

import com.fmy.mcsecurity.integration.TypeIntegration;
import com.fmy.mcsecurity.integration.TypeIntegrationHolder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import java.util.Map;

/**
 * @author Mr.fmy
 * @version 1.0.0
 * @ClassName McSecurityInitConfig
 * @Description TODO 初始化配置
 * @createTime 2020/4/15 09:51
 */
public class McSecurityInitConfig implements ApplicationListener<ContextRefreshedEvent> {

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        ApplicationContext context = contextRefreshedEvent.getApplicationContext();
        typeIntegration(context);
    }

    /**
     * 初始化 {@link TypeIntegration}
     */
    private void typeIntegration(ApplicationContext context) {
        Map<String, TypeIntegration> typeIntegrationMap = context.getBeansOfType(TypeIntegration.class);
        if (typeIntegrationMap != null) {
            TypeIntegrationHolder.setAuthenticators(typeIntegrationMap.values());
        }
    }
}
